<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
 
</head>
<body>
    <script>
    	<!--验证API-->
        function myFunction() {
            var inpObj = document.getElementById("id1");
            
            inpObj.willValidate = true;
 
            if (inpObj.checkValidity() == false) {
                document.getElementById("demo").innerHTML = inpObj.validationMessage;
            }else {
                document.getElementById("demo").innerHTML = "输入正确";
            }
            
            if (false == inpObj.validity.valid) {
                alert("输入不合法");
            } else {
                alert("输入合法");
            }
        }
    </script>
    	要求输入的值必须在100~300之间<br />
    <input id="id1" type="number" min="100" max="300" required>
    <button onclick="myFunction()">验证</button>
    <p id="demo"></p>
</body>
</html>